View Javadoc

1   package ar.com.epere4.util.collections;
2   
3   import java.util.Iterator;
4   
5   import org.apache.commons.collections.MapIterator;
6   import org.apache.commons.lang.Validate;
7   
8   /***
9    * This class wraps a MapIterator so it returns the values it has.
10   * 
11   * @author epere4
12   * @since 20/02/2006
13   */
14  public class MapValuesIterator implements Iterator {
15      /*** The field where we store the original {@link MapIterator} instance. */
16      private MapIterator mapIterator;
17  
18      /***
19       * 
20       * @param mapIterator
21       *            the mapIterator this map wraps.
22       * @since 20/02/2006
23       */
24      public MapValuesIterator(final MapIterator mapIterator) {
25          Validate.notNull(mapIterator, "mapIterator can't be null");
26          this.mapIterator = mapIterator;
27      }
28  
29      /***
30       * {@inheritDoc}
31       * 
32       * @see java.util.Iterator#hasNext()
33       * @since 20/02/2006
34       */
35      public boolean hasNext() {
36          return mapIterator.hasNext();
37      }
38  
39      /***
40       * This method returns the same value that {@link MapIterator#getValue()}
41       * does.
42       * 
43       * @return the same value that {@link MapIterator#getValue()} does.
44       * @see java.util.Iterator#next()
45       * @since 20/02/2006
46       */
47      public Object next() {
48          mapIterator.next(); // must be called before getValue()
49          return mapIterator.getValue();
50      }
51  
52      /***
53       * {@inheritDoc}
54       * 
55       * @see java.util.Iterator#remove()
56       * @since 20/02/2006
57       */
58      public void remove() {
59          mapIterator.remove();
60      }
61  
62  }